//


#import "AM_HomeTableViewCell.h"

//
@interface AM_HomeTableViewCell ()
/** <#Description#>*/
@property (nonatomic, strong) UIImageView *IMG;
/** <#Description#>*/
@property (nonatomic, strong) UILabel *accountLabel;
/** <#Description#>*/
@property (nonatomic, strong) UILabel *passwordLabel;


@end

@implementation AM_HomeTableViewCell

// 初始化cell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self createTableViewCell];
    }
    return self;
}

// 初始化
-(void)createTableViewCell {
    //
    self.IMG = ({
        UIImageView *img = [[UIImageView alloc]init];
        img.backgroundColor = [UIColor grayColor];
        [self.contentView addSubview:img];
        img;
    });
    //
    self.accountLabel = ({
        UILabel *label = [[UILabel alloc]init];
        label.textColor = RGB(60, 60, 60);
        label.font = FontPFRegular(kRelativeWidth(15));
        label.text = @"Account:4774387493";
        [self.contentView addSubview:label];
        label;
    });
    //
    self.passwordLabel = ({
        UILabel *label = [[UILabel alloc]init];
        label.textColor = RGB(60, 60, 60);
        label.font = FontPFRegular(kRelativeWidth(15));
        label.text = @"Password:ansjalsjlff23";
        [self.contentView addSubview:label];
        label;
    });
   
    
}

- (void)setNeedsLayout {
    [super setNeedsLayout];
    //
    [self.IMG mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_offset(kRelativeHeight(10));
        make.left.mas_offset(kRelativeWidth(12));
        make.width.height.mas_equalTo(kRelativeWidth(50));
    }];
    //
    [self.accountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_offset(kRelativeHeight(10));
        make.left.mas_equalTo(self.IMG.mas_right).offset(kRelativeWidth(10));
        make.height.mas_equalTo(kRelativeHeight(20));
    }];
    //
    [self.passwordLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.accountLabel.mas_bottom).offset(kRelativeHeight(10));
        make.left.mas_equalTo(self.accountLabel);
        make.height.mas_equalTo(kRelativeHeight(20));
    }];
    
}

//set
- (void)setModel:(HomeData *)model {
    //
    self.accountLabel.text = [NSString stringWithFormat:@"Account：%@",model.account];
    self.passwordLabel.text = [NSString stringWithFormat:@"Password：%@",model.password];
    //
    NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
    // 读取沙盒路径图片
    NSString *imageFilePath = [path stringByAppendingPathComponent:model.img ];
    UIImage *imgFromUrl=[[UIImage alloc]initWithContentsOfFile:imageFilePath];
    self.IMG.image = imgFromUrl;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
